/**
 * @file 表格插件
 * @desc 表格数据均为异步加载，支持查询事件
 * @author yangjiangming <449654337@qq.com>
 * @date 2018/11/27 10:20:40
 */
layui.define(['form', 'laydate', 'layer', 'zmnUtils', 'tooltipster'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var laydate = layui.laydate;
    var zmnUtils = layui.zmnUtils;

    /**
     * 渲染日期选择器
     * @param selector 日期选择器的选择器或者 Dom 对象
     */
    var _renderDatePicker = (function () {
        function _render (selector) {
            var config = {
                elem: selector,
                format: selector.indexOf('Start') !== -1 ? 'yyyy-MM-dd' : 'yyyy-MM-dd'
            };
            var $selector = $(selector);
            if ($selector) {
                var minTime = $selector.data('min') || defaultMinTime;
                if (minTime) {
                    config.min = minTime;
                }
            }

            laydate.render(config);
        }


        return function (selectors) {
            if (zmnUtils.isString(selectors)) {
                _render(selectors);
                return;
            }

            if (zmnUtils.isArray(selectors)) {
                $.each(selectors, function (index, keyword) {
                    $.each(['Start', 'End'], function (i, suffix) {
                        _render('#' + keyword + suffix);
                    });
                });
            }
        }
    })();

    /**
     * 整理查询参数
     * @private
     */
    function _normalizeSearchParams () {

    }

    exports('zmnSearch', {
        renderDatePicker: _renderDatePicker,
        parseParams: _normalizeSearchParams
    });
});